package com.ywjh.inter.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ywjh.inter.service.SettingService;
import com.ywjh.inter.utils.StrUtil;

import net.sf.json.JSONObject;

public class Version extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7079905309815481389L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html; charset=utf-8");
		int r = 0;
		String e = "";

		JSONObject postData = StrUtil.getPostJSON(req);
		String act = postData.getString("act");
		JSONObject json = new JSONObject();
		switch (act) {
		case "APP_DOC":
			JSONObject doc_ver = SettingService.getInstance().getAppDoc();
			r = 1;
			if (doc_ver != null) {
				json.put("d", doc_ver);
			} else {
				e="没有版本信息";
			}
			break;
		case "APP_PATIENT":
			r = 1;
			JSONObject patient_ver = SettingService.getInstance().getAppPatient();
			if (patient_ver != null) {
				json.put("d", patient_ver);
			} else {
				e="没有版本信息";
			}
			break;
		}
		json.put("r", r);
		json.put("e", e);
		PrintWriter pw = resp.getWriter();
		pw.write(json.toString());
		pw.flush();
		pw.close();
	}
}
